package com.toune.villager.activity

import android.os.Bundle
import android.os.CountDownTimer
import com.tamsiree.rxkit.RxActivityTool
import com.toune.villager.R
import com.toune.dltools.ui.DLBaseActivity
import com.toune.dltools.ui.DLBaseViewModel
import kotlinx.android.synthetic.main.activity_splash.*

class SplashActivity : DLBaseActivity<DLBaseViewModel>() {

    var countDownTimer: CountDownTimer? = null
    var isJump = false

    override fun onDestroy() {
        if (countDownTimer != null) {
            countDownTimer!!.cancel()
        }
        super.onDestroy()
    }

    override val layout: Int
        get() = R.layout.activity_splash
    override val titleStr: String?
        get() = ""

    override fun init(savedInstanceState: Bundle?) {
        countDownTimer = object : CountDownTimer(1000L, 1000L) {
            override fun onFinish() {
                if (!isJump) {
                    RxActivityTool.skipActivityAndFinish(
                        this@SplashActivity,
                        LoginActivity::class.java
                    )
                    isJump = true
                }
            }

            override fun onTick(millisUntilFinished: Long) {
                jumpTv.text = "跳过 ${millisUntilFinished / 1000}"
            }
        }
        countDownTimer!!.start()

        jumpTv.setOnClickListener {
            if (!isJump) {
                RxActivityTool.skipActivityAndFinish(this@SplashActivity, LoginActivity::class.java)
                isJump = true
            }
        }
    }

    override fun initEventAndData() {
    }
}